import java.util.HashMap;
import java.util.Map;

public class Solution1218 {
    public int longestSubsequence(int[] arr, int difference) {
        Map<Integer,Integer> map=new HashMap<>();
        int ans=0;
        for (int i : arr) {
            int count=map.getOrDefault(i-difference,0);
            map.put(i,count+1);
            ans=Math.max(ans,count+1);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1218().longestSubsequence(new int[]{1,2,3,4},1));
    }
}
